package com.woyowodaows.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.woyowodaows.R;
import com.woyowodaows.weight.GlideCircleTransform;


import java.io.File;


/**
 * @author haiwei
 *         图片加载工具类
 */

public class ImageLoaderUtlis {

    public static void displayImage(Context context, String imageUrl,int errorImageId, ImageView imageView){
        Glide.with(context).load(imageUrl).placeholder(errorImageId).
                error(errorImageId).into(imageView);
    }

    public static void displayImage(Context context, String imageUrl, ImageView imageView){
        Glide.with(context).load(imageUrl).placeholder(R.mipmap.ic_launcher).
                error(R.mipmap.ic_launcher).into(imageView);
    }

    public static void displayLocalImage(Context context, String imageUrl,int errorImageId,ImageView imageView){
        Glide.with(context).load(imageUrl)
                .error(errorImageId).into(imageView);
    }

    public static void displayLocalImage(Context context, File imageUrl, int errorImageId, ImageView imageView){
        Glide.with(context).load(imageUrl)
                .error(errorImageId).into(imageView);
    }

    /**
     * 加载圆形图片
     * @param context
     * @param imageUrl
     * @param errorImageId
     * @param imageView
     */
    public static void displayHeadImage(Context context, String imageUrl,int errorImageId, ImageView imageView){
        Glide.with(context).load(imageUrl).asBitmap().centerCrop().skipMemoryCache(true).
                diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(errorImageId).
                error(errorImageId).
                transform(new GlideCircleTransform(context)).
                into(imageView);
    }

}
